package com.xq.spring.beans;

import java.lang.reflect.Field;

import org.springframework.beans.factory.FactoryBean;

/**
 * 获取属性的工厂Bean类.
 * @author 郭凯强
 */
public class GetFieldFactoryBean implements FactoryBean<Object>{

	private String className=null;
	private String fieldName=null;
	
	
	public void setClassName(String className) {
		this.className = className;
	}


	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	/** 返回工厂Bean的产品.
	 * @see org.springframework.beans.factory.FactoryBean#getObject()
	 */
	@Override
	public Object getObject() throws Exception {
		Class<?> targetClass=Class.forName(className);
		Field field=targetClass.getField(fieldName);
		return field.get(null); //获取静态属性
	}


	/** 返回工厂Bean的产品类型.
	 * @see org.springframework.beans.factory.FactoryBean#getObjectType()
	 */
	@Override
	public Class<?> getObjectType() {
		return Object.class;
	}

	/** 工厂Bean的产品是否为单例.
	 * @see org.springframework.beans.factory.FactoryBean#isSingleton()
	 */
	@Override
	public boolean isSingleton() {
		return false;
	}

}
